//
//  MatchCustom.m
//  cutter
//
//  Created by mac on 16/1/6.
//  Copyright © 2016年 e360. All rights reserved.
//
#import "AppData.h"
#import "MatchCustom.h"
#import "TMCutterLayer.h"


@implementation MatchSortPrice
-(void)layoutSubviews{
    UIImage *img = [self imageForState:self.state];
    if (img) {
        [self setTitleEdgeInsets:UIEdgeInsetsMake(0, -img.size.width, 0, img.size.width)];
        [self setImageEdgeInsets:UIEdgeInsetsMake(0, self.titleLabel.bounds.size.width + 4, 0, -self.titleLabel.bounds.size.width - 4)];
    }
    if (self.selected) {
        if (self.sort) {
            [self.imageView setTransform:CGAffineTransformMakeScale(1, 1)];
        }else{
            [self.imageView setTransform:CGAffineTransformMakeScale(1,-1)];
        }
    }
    [super layoutSubviews];
}
@end


@implementation MatchCustomView
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //
    if (self.presentationController) {
        UIView *parent = [[self.navigationController view] superview];
        if (parent) {
            [parent.layer setCornerRadius:6];
        }
    }
}
@end

//
@implementation MatchCustomTable
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //
    if (self.presentationController) {
        UIView *parent = [[self.navigationController view] superview];
        if (parent) {
            [parent.layer setCornerRadius:6];
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 0.1;
    }
    return tableView.sectionHeaderHeight;
}
@end


//过渡
@implementation MatchCustomSegue
- (void)perform{
    UIViewController *source = self.sourceViewController;
    UIViewController *destination = self.destinationViewController;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
        UIViewController *controller = [[source.view window] rootViewController];
        if (controller) {
            [controller setModalPresentationStyle:UIModalPresentationCurrentContext];
            [controller presentViewController:destination animated:NO completion:nil];
        }
    }else{
        [destination setModalPresentationStyle:UIModalPresentationOverCurrentContext];
        [source presentViewController:destination animated:NO completion:nil];
    }
}
@end


//
@implementation MatchMutableButton
-(void)layoutSubviews{
    [super layoutSubviews];
    if (self.selected && self.highlighted) {
        UIImage *img = [self imageForState:UIControlStateDisabled];
        if (img) {
            [self.imageView setImage:img];
        }
    }
}
@end
//
//
@implementation MatchCustomButton
- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if (self.selected) {
        [self setBackgroundColor:self.selectedBackgroundColor];
    }else{
        [self setBackgroundColor:self.nomalBackgroundColor];
    }
}
-(void)setHighlighted:(BOOL)highlighted{
    [super setHighlighted:highlighted];
    if (self.highlighted) {
        [self setBackgroundColor:self.selectedBackgroundColor];
    }else{
        if (self.selected == NO) {
            [self setBackgroundColor:self.nomalBackgroundColor];
        }
    }
}
@end